#include <iostream>
#include <stdio.h>
#include <string>
//#include <math.h>
using namespace std;

int ans[10000005];
int flag[10000005];
int main()
{
	int i, j, tot, head, tail;
	ans[1] = 1;
	ans[2] = 3;
	ans[3] = 4;

	
	tail = 3;
	int p1, p2, v1, minv, v2;
	
//	memset(flag, 0, sizeof(flag));

	p1 = 2;
	p2 = 3;
	while (tail <=10000001)
 	{
 		if (flag[p1]==0)
 		{
 		    flag[p1] = 1;
 		    ans[++tail] = ans[p1]*2+1;
 		}    
 		else if (flag[p1]==1)
 		{
 		    v1 = ans[p1]*3+1;
 		    
 		    while (flag[p2]==1 && ans[p2]<ans[p1]*2) p2 ++;
 		    v2 = ans[p2]*2+1;
 		    minv = v1 < v2 ? v1 : v2;
 		    if (minv == v1)
 		    {
 		//        flag[p1] = 2;
 		        p1++;
 		    }    
 		    if (minv == v2)
 		    {
 		     	flag[p2] = 1;   
 		    }    
 		    ans[++tail] = minv;
 		}    
 		else
 			p1++;
	//	if (tail%10000==0) cout << tail << endl;
       
    }     	
    
/*   	for (i=1; i<=100; ++i)
   		cout <<ans[i] << " ";
  		
   	cout << endl;
 */
    while (cin>>i)
    	cout << ans[i] << endl; 
    
    return 0;
}    


